﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace WpfApp_MvvmPatten.ViewModel
{
    public class ScottPlotViewModel
    {
        public ObservableCollection<double> Lines { get; set; }

        public ScottPlotViewModel()
        {
            Lines = new ObservableCollection<double>(GetRandom(10));

            Task.Run(async () => 
            {
                while (true) 
                {
                    await Task.Delay(2000);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        Lines.Add(new Random().Next(0, 10));
                        Lines.RemoveAt(0);
                    });
                }
            });

           
        }


        private double[] GetRandom(int length)
        {
            double[] _datas = new double[length];
            for (int i = 0; i < length; i++)
            {
                _datas[i] = new Random().Next(1, 10);
            }
            return _datas;
        }
    }
}
